﻿using NLog;
using System;
using System.Windows;

namespace IOA.MES.WebTool.Common
{
    public static class CommonMessage
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// 弹出窗
        /// </summary>
        /// <param name="msg">弹出信息</param>
        /// <param name="showMessageBox">是否弹窗：默认true</param>
        /// <param name="ex">异常信息</param>
        public static void Alert(string msg, bool showMessageBox = true, Exception ex = null)
        {
            Log(LogLevel.Fatal, msg, ex);
            if (showMessageBox)
            {
                MessageBox.Show(msg);
            }
        }

        /// <summary>
        /// 打印日志
        /// </summary>
        /// <param name="level">日志级别</param>
        /// <param name="msg">日志信息</param>
        /// <param name="ex">异常</param>
        public static void Log(LogLevel level, string msg, Exception ex = null)
        {
            logger.Log(level, ex, msg);
        }
    }
}
